package edu.spbsu.nonsm00th.algorithms.sort.impl;

import edu.spbsu.nonsm00th.algorithms.sort.Comparator;
import edu.spbsu.nonsm00th.model.enums.Ratio;

/**
 * Long comparator - will use only for test.
 * null elements are same with 0L.
 * 
 * @author mbuzdov
 */
public class ComparatorLong implements Comparator<Long> {

    public Ratio compare(Long obj1, Long obj2) {
        Long nonull1 = replaceNullWithZero(obj1);
        Long nonull2 = replaceNullWithZero(obj2);
        if (nonull1.longValue() > nonull2.longValue()) {
            return Ratio.GREATER;
        }
        if (nonull1.longValue() < nonull2.longValue()) {
            return Ratio.LESS;
        }
        return Ratio.EQUAL;
    }

    private Long replaceNullWithZero(Long value) {
        return null == value ? 0L : value;
    }
}
